package gateway.mgt

import gateway.mgt.api.ApiGroup
import grails.testing.gorm.DomainUnitTest
import spock.lang.Specification

class ApiGroupSpec extends Specification implements DomainUnitTest<ApiGroup> {

    static final ValidPropertiesSet = [
            [name: "default"]
    ]

    static final InvalidPropertiesSet = [
            [name: null, expected_error_counter: 1]
    ]

    def setup() {
    }

    def cleanup() {
    }

    void "test a valid properties"() {
        given:
        def instance = new ApiGroup(params)

        when:
        instance.save(flush: true)

        then:
        !instance.hasErrors()

        where:
        params << ValidPropertiesSet
    }

    void "test an invalid properties"() {
        given:
        def instance = new ApiGroup(params)

        when:
        instance.save(flush: true)

        then:
        instance.hasErrors()

        and:
        instance.errors.allErrors.size() == params.expected_error_counter

        where:
        params << InvalidPropertiesSet
    }
}
